﻿<cfsilent>
	<cfscript>
	
		event.setArg("pageTitle", "教学运行基础数据 - 学期数据维护");

		sql = "SELECT
					t.term_id,t.academic_year,t.academic_term,t.term_start,t.term_weeks,t.term_prop
				FROM
					t_term t
				WHERE
					SUBSTR(t.academic_year,1,4) > :yearStart AND SUBSTR(t.academic_year,1,4) < :yearEnd 
				ORDER BY
					t.term_id";

		queryObj = new Query( datasource=application.dnsSlave ); 
		queryObj.addParam( name="yearStart", value=(year(now())-2), cfsqltype="cf_sql_char" );
		queryObj.addParam( name="yearEnd", value=(year(now())+2), cfsqltype="cf_sql_char" );
		rs_term = queryObj.execute( sql=sql ).getResult();

		dictAdvice = getProperty("serviceFactory").getBean("senateDictionaryAdvice");
		datetimeAdvice = getProperty("serviceFactory").getBean("datetimeAdvice");
		propAdvice = getProperty("serviceFactory").getBean("termPropertyAdvice");

		targetArgs = structNew();

	</cfscript>
</cfsilent>

<div id="headArea">
	<div class="uiHeader uiHeaderWithImage ptm">
		<div class="clearfix uiHeaderTop">
			<div class="uiHeaderActions rfloat">
				<a class="uiButton" href="<cfoutput>#buildURL('planSchema')#</cfoutput>"><i class="mrs img btnPublish"></i><span class="uiButtonText">教学计划</span></a>
			</div>
			<div>
				<h2 class="uiHeaderTitle">
					<i class="uiHeaderImage img icon16x16 card"></i>学期设置
				</h2>
			</div>
		</div>
	</div>
</div>

<div class="UIElement">
	<ul class="senateFirstPage">
		<li>
			<div class="clearfix" id="summary">
				<div class="UItab">
					<div class="tabLables">
						<span class="active">学期设置</span>
					</div>
				</div>
				
				<div id="editBox" class="tabContentBox hidden_elem">
					<form id="formEdit" onSubmit="javascript:return processVerfiyForm('formEdit');" class="formWrapper" method="post" action="<cfoutput>#buildURL('programTermUpdateDo')#</cfoutput>">
						
						<input type="hidden" id="TermID" name="TermID" value="" />
						
						<div class="label">
							<span class="req">*</span><b>开学日期</b>
							<input name="DateStart" id="DateStart" type="text" class="typeDate" verification="date" maxlength="10" value="" /><span id="calendarTrigger" class="btnCalendar"></span>
						</div>
						
						<div class="label">
							<span class="req">*</span><b>运行周次</b>
							<input name="Weeks" id="Weeks" type="text" class="typeTinyInt" verification="integer" maxlength="2" value="" />
						</div>
						
						<hr/>
						
						<div class="lable">
							<input class="button" type="submit" value="更新" />
							<input id="formReset" class="button" type="reset" value="返回" />
						</div>
						
					</form>
					<script language="javascript" type="text/javascript">
						//<![CDATA[
						<!--
						$(document).ready(function() {
							Calendar.setup({
								trigger    : "calendarTrigger",
								inputField : "DateStart",
								animation  : false
								});

						});
						// -->
						//]]>
					</script>
								
				</div>
				
				<div id="listBox" class="tabContentBox">
				
					<cfif rs_term.recordCount>
						
						<cfset row = 0 />
						<table class="UIEditable">
							<thead>
								<tr>
									<td width="18"></td>
									<td width="80">学年</td>
									<td width="120">学期</td>
									<td width="120">开学日期</td>
									<td>周次</td>
									<td width="30">运行</td>
									<td width="30">排课</td>
									<td width="30">排考</td>
									<td width="30">选课</td>
									<td width="30">补考</td>
									<!---<td width="30">期中</td>--->
									<td width="30">结算</td>
									<td width="18"></td>
								</tr>
							</thead>
							<tbody>
								<!---<cfloop array="#termArray#" index="term">--->
                                <cfloop query="rs_term">
									<cfset row++ />
									
									<cfset structInsert(targetArgs, "TID", rs_term.term_id, true) />
									<cfset propAdvice.parseProperty(rs_term.term_prop) />
									
									<tr class="editRows <cfif event.getArg('TID') eq rs_term.term_id> lastEdited</cfif>" rowid="<cfoutput>#rs_term.term_id#</cfoutput>">
										<td class="index"><cfoutput>#row#</cfoutput></td>
										<td><span class="numeric"><cfoutput>#rs_term.academic_year#</cfoutput></span></td>
										<td><cfoutput>#dictAdvice.getTerm(rs_term.academic_term)#</cfoutput></td>
										<td column="DateStart"><span class="numeric"><cfoutput>#datetimeAdvice.formatDateString(rs_term.term_start)#</cfoutput></span></td>
										<td column="Weeks"><span class="numeric"><cfoutput>#rs_term.term_weeks#</cfoutput></span></td>
										<td>
											<cfif propAdvice.getRunning()>
												<a href="javascript:void(0);" class="stat on" usage="Running" rowid="<cfoutput>#rs_term.term_id#</cfoutput>"></a>
												<cfelse>
												<a href="javascript:void(0);" class="stat off" usage="Running" rowid="<cfoutput>#rs_term.term_id#</cfoutput>"></a>
											</cfif>
										</td>
										<td>
											<cfif propAdvice.getForCourse()>
												<a href="javascript:void(0);" class="stat on" usage="ForCourse" rowid="<cfoutput>#rs_term.term_id#</cfoutput>"></a>
												<cfelse>
												<a href="javascript:void(0);" class="stat off" usage="ForCourse" rowid="<cfoutput>#rs_term.term_id#</cfoutput>"></a>
											</cfif>
										</td>
										<td>
											<cfif propAdvice.getForExam()>
												<a href="javascript:void(0);" class="stat on" usage="ForExam" rowid="<cfoutput>#rs_term.term_id#</cfoutput>"></a>
												<cfelse>
												<a href="javascript:void(0);" class="stat off" usage="ForExam" rowid="<cfoutput>#rs_term.term_id#</cfoutput>"></a>
											</cfif>
										</td>
										<td>
											<cfif propAdvice.getForChoose()>
												<a href="javascript:void(0);" class="stat on" usage="ForChoose" rowid="<cfoutput>#rs_term.term_id#</cfoutput>"></a>
												<cfelse>
												<a href="javascript:void(0);" class="stat off" usage="ForChoose" rowid="<cfoutput>#rs_term.term_id#</cfoutput>"></a>
											</cfif>
										</td>
										<td>
											<cfif propAdvice.getForResitExam()>
												<a href="javascript:void(0);" class="stat on" usage="ForResitExam" rowid="<cfoutput>#rs_term.term_id#</cfoutput>"></a>
												<cfelse>
												<a href="javascript:void(0);" class="stat off" usage="ForResitExam" rowid="<cfoutput>#rs_term.term_id#</cfoutput>"></a>
											</cfif>
										</td>
										<!---<td>
											<cfif propAdvice.getForHalfExam()>
												<a href="javascript:void(0);" class="stat on" usage="ForHalfExam" rowid="<cfoutput>#rs_term.term_id#</cfoutput>"></a>
												<cfelse>
												<a href="javascript:void(0);" class="stat off" usage="ForHalfExam" rowid="<cfoutput>#rs_term.term_id#</cfoutput>"></a>
											</cfif>
										</td>--->
										<td>
											<cfif propAdvice.getForCharge()>
												<a href="javascript:void(0);" class="stat on" usage="ForCharge" rowid="<cfoutput>#rs_term.term_id#</cfoutput>"></a>
												<cfelse>
												<a href="javascript:void(0);" class="stat off" usage="ForCharge" rowid="<cfoutput>#rs_term.term_id#</cfoutput>"></a>
											</cfif>
										</td>
										<td><a class="operation" href="javascript:void(0);" rowid="<cfoutput>#rs_term.term_id#</cfoutput>"></a></td>
									</tr>
								</cfloop>
							</tbody>
						</table>
						
						<script language="javascript" type="text/javascript">
							//<![CDATA[
							<!--
							$(document).ready(function() {
								
								/* */
								$("a.operation").click(function(){
									
									var rowid = $(this).attr("rowid");
									var $row = $("tr.editRows[rowid='" + rowid + "']");
									
									$("input#TermID").val(rowid);
									$("input#DateStart").val($("td[column='DateStart']", $row).text());
									$("input#Weeks").val($("td[column='Weeks']", $row).text());
									
									$("#editBox").removeClass("hidden_elem");
									$("#listBox").addClass("hidden_elem");
									
								});
								
								/**/
								$("#formReset").click(function(){
									$("#listBox").removeClass("hidden_elem");
									$("#editBox").addClass("hidden_elem");
								});

								/* term prop trigger */
								$("a[usage]").click(function(){
									
									var rowid = $(this).attr("rowid");
									var method = $(this).attr("usage");
										
									var status = $(this).hasClass("on");
										
									var newStatus = true;
									
									var $row = $("tr.editRows[rowid='" + rowid + "']");
									
									/* 切换状态数据 */
									if (status) {
										newStatus = false;
									}
									
									/* 如果当前点击属于 设置更改活动学期数据 */
									if (newStatus) {

										/* 发送请求 */
										$(this).removeClass("off").removeClass("on").addClass("waiting");
									
										$.post(
												"<cfoutput>#buildURL('apiTermPropChange')#</cfoutput>", 
												{
													'tid' : rowid,
													'prop' : method,
													'status' : newStatus,
													'seed': (new Date()).getTime()
												}, 
												function(data) {

													result = $.parseJSON(data);
													
													$(this).removeClass("waiting");
												
													/* 刷新学期状态数据 */
													if (result.Running) { $("a[usage='Running']").removeClass("on").addClass("off"); $("a[usage='Running']", $row).removeClass("off").addClass("on"); } else { $("a[usage='Running']", $row).removeClass("on").addClass("off"); }
													
													if (result.ForCourse) { $("a[usage='ForCourse']").removeClass("on").addClass("off"); $("a[usage='ForCourse']", $row).removeClass("off").addClass("on"); } else { $("a[usage='ForCourse']", $row).removeClass("on").addClass("off"); }
													if (result.ForExam) { $("a[usage='ForExam']").removeClass("on").addClass("off"); $("a[usage='ForExam']", $row).removeClass("off").addClass("on"); } else { $("a[usage='ForExam']", $row).removeClass("on").addClass("off"); }
													if (result.ForChoose) { $("a[usage='ForChoose']").removeClass("on").addClass("off"); $("a[usage='ForChoose']", $row).removeClass("off").addClass("on"); } else { $("a[usage='ForChoose']", $row).removeClass("on").addClass("off"); }
													if (result.ForHalfExam) { $("a[usage='ForHalfExam']").removeClass("on").addClass("off"); $("a[usage='ForHalfExam']", $row).removeClass("off").addClass("on"); } else { $("a[usage='ForHalfExam']", $row).removeClass("on").addClass("off"); }
													if (result.ForResitExam) { $("a[usage='ForResitExam']").removeClass("on").addClass("off"); $("a[usage='ForResitExam']", $row).removeClass("off").addClass("on"); } else { $("a[usage='ForResitExam']", $row).removeClass("on").addClass("off"); }
													if (result.ForCharge) { $("a[usage='ForCharge']").removeClass("on").addClass("off"); $("a[usage='ForCharge']", $row).removeClass("off").addClass("on"); } else { $("a[usage='ForCharge']", $row).removeClass("on").addClass("off"); }
													

												});
										
										}
									
								});
								
							});
							// -->
							//]]>
						</script>
						
					</cfif>
				
				</div>
				
			</div>
		</li>
	</ul>
</div>
